const { app, ipcRenderer } = window.require("electron");
import { useEffect, useState } from "react";
import { history,useModel } from "umi";
import DeviceInfo from '../layouts/mainLayout/components/deviceInfo/index';

export default () => {
  const [snapShotName, setSnapShotName] = useState<string>();
  const [localPath,setLocalPath]=useState<string>();
  const {
    deviceList,
    getDeviceList,
    getDeviceInfo,
    deviceInfo,
    setDeviceInfo,
  } = useModel("device");
  useEffect(() => {
    if (history.location.pathname === "/auth") {
      setSnapShotName('');
    }
  }, [history,deviceInfo?.SN]);
/*
  const getSnapShotName = async (taskName: string, SN: string, OS: string,testType:string) => {
    try {
      let {localPath,snapShotName} = await ipcRenderer.invoke(
        "getSnapShotByHdc",
        taskName,
        SN,
        OS,
        testType
      );
      console.log("*****11**1**1**",localPath,snapShotName)
      if(localPath?.length){
        setLocalPath(localPath);
      }
      if (snapShotName?.length) {
        setSnapShotName(snapShotName);
      } */
  const getSnapShotName = async (taskName: string,testType:string) => {
    try {
      let {localPath,snapShotName} = await ipcRenderer.invoke(
        "getSnapShotByHdc",
        taskName,
        deviceInfo?.SN,
        deviceInfo?.OS,
        testType
      );
      console.log("*****11**1**1**",localPath,snapShotName)
      if(localPath?.length){
        setLocalPath(localPath);
      }
      if (snapShotName?.length) {
        setSnapShotName(snapShotName);
      }
      /*else{
                setAppList(await ipcRenderer.invoke("getAllAppListAdb"));
            }*/
    } catch (err) {
      console.log(err);
    }
  };

  return { snapShotName, setSnapShotName, getSnapShotName, localPath,setLocalPath};
};
